﻿using StockModel;
using Utils;

namespace StockEngine.Extensions
{
	internal static class StockGroupExtension
	{
		public static void ClearStocks(this StockGroup group)
		{
			// Check to avoid rising a reset event if its not needed
			ObservableCollection2<StockGroupItem> items = group.Items.GetWriteLock();
			try
			{
				if (items.Count != 0)
				{
					foreach (StockGroupItem stockGroupItem in items)
					{
						stockGroupItem.Item.Dispose();
					}
					items.Clear();
				}
			}
			finally
			{
				group.Items.FreeWriteLock();
			}
		}
	}
}
